package com.wn.airplane_mode.receiver;

import com.wn.airplane_mode.tool.AirplaneTaskObj;


/**
 * @author Grant Woo
 * 关闭飞行模式*/
public class AirplaneModeOffReceiver extends AirplaneModeOpReceiver {

	@Override
	public boolean canDo(AirplaneTaskObj obj) {
		return !obj.isTurnOffExecuted() && tool.isAirPlaneModeOn();
	}

	@Override
	public boolean turnOn() {
		return false;
	}

	@Override
	public boolean rightTime(String time_now,String time_on,String time_off) {
		if(before(time_off, time_on)){
			return afterOrEqual(time_now, time_off) && before(time_now, time_on);
		}else{
			return   
			((afterOrEqual(time_now, time_off) && beforeOrEqual(time_now, MIDNIGHT))||
					(afterOrEqual(time_now, MORNING) && before(time_now, time_on)));
			
		}
		
	}

	@Override
	public void setAutoExecuted(AirplaneTaskObj obj) {
		obj.setTurnOffExecuted(true);
		tool.setTaskObjStr(obj);
		//在v2.1.7增加
		for(int i=1;i<=7;i++){
			if(i != obj.getDayId()){
				AirplaneTaskObj aobj = new AirplaneTaskObj(tool.getTaskObjStr(i));
				aobj.setTurnOffExecuted(false);
				tool.setTaskObjStr(aobj);
			}
		}
	}
}
